//
//  TTShoutOutPriceViewCell.m
//  TaoTuo
//
//  Created by zhaoshijie on 2020/9/7.
//  Copyright © 2020 刘广. All rights reserved.
//

#import "TTShoutOutPriceViewCell.h"
#import "TTLeadingLabelView.h"

@interface TTShoutOutPriceViewCell ()

@property (nonatomic, strong) UILabel *moneyLabel;
@property (nonatomic, strong) TTLeadingLabelView *leadingView;
@property (nonatomic, strong) UILabel *dateLabel;

@property (nonatomic, strong) TTRecyclingDetailPriceListModel *model;

@end

@implementation TTShoutOutPriceViewCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {

        [self setupSubviews];

    }
    return self;
}

- (void)setModel:(TTRecyclingDetailPriceListModel *)model priceDifference:(CGFloat)priceDifference
{
    _model = model;
    NSString *priceStr = [NSString stringWithFormat:@"¥%@", model.Price];
    NSMutableAttributedString *attr = [[NSMutableAttributedString alloc] initWithString:priceStr];
    [attr addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:8] range:[priceStr rangeOfString:@"¥"]];
    self.moneyLabel.attributedText = attr;
    
    self.dateLabel.text = model.CreateTime;
    
    if (!model.isShowRanking) {
        self.leadingView.hidden = YES;
        self.moneyLabel.textColor = UIColorHex(333333);
        self.dateLabel.textColor = UIColorHex(333333);
    } else {
        NSString *str = @"已落后";
        NSString *pd = [NSString stringWithFormat:@"¥%.0f", priceDifference];
        UIColor *color = UIColorHex(409400);
        if (priceDifference > 0) {
            str = @"已领先";
            pd = @"";
            color = UIColorHex(DF4343);
        }
        NSString *t = [NSString stringWithFormat:@"%@%@", str, pd];
        [self.leadingView setTitle:t titleColor:color imageName:str];
        self.moneyLabel.textColor = UIColorHex(DF4343);
        self.dateLabel.textColor = UIColorHex(DF4343);
    }

    

}

- (void)setupSubviews
{
    [self.moneyLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(15);
        make.centerY.equalTo(self.contentView);
    }];

    [self.leadingView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.moneyLabel.mas_right).mas_offset(20);
        make.centerY.equalTo(self.contentView);
    }];

    [self.dateLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self.contentView.mas_right).mas_offset(-15);
        make.centerY.equalTo(self.contentView);
    }];
}

- (UILabel *)moneyLabel
{
    if (!_moneyLabel) {
        _moneyLabel = [UILabel labelWithTitle:@"" color:UIColorHex(333333) fontSize:14];
        [self.contentView addSubview:_moneyLabel];
    }
    return _moneyLabel;
}

- (TTLeadingLabelView *)leadingView
{
    if (!_leadingView) {
        _leadingView = [[TTLeadingLabelView alloc] init];
        [self addSubview:_leadingView];
    }
    return _leadingView;
}

- (UILabel *)dateLabel
{
    if (!_dateLabel) {
        _dateLabel = [UILabel labelWithTitle:@"" color:UIColorHex(333333) fontSize:13];
        [self.contentView addSubview:_dateLabel];
    }
    return _dateLabel;
}


@end
